﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    class DSTDYARNReport : BaseReport
    {
        #region ----------------PROPERTIES----------------------------------
        public OracleConnection OracleDB;
        public OracleCommand orlReadCommand = new OracleCommand();
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        public DataSet dsResult;
        public DataSet setUI = new DataSet();
        string ABPAUFFKRS;
        string ABPAUFFLFD;
        string ABPAUFFPOS;
        string DocType;
        string CellName = "";
        string CellValue = "";
        string strCompany;
        string strExcelFile;
        #endregion
        public DSTDYARNReport()
            : base()
        {
        }
        public DSTDYARNReport(Dictionary<string, object> dicParamater)
            : base(dicParamater)
        {
            DocType = dicParamater["DocType"].ToString().Trim();
            strCompany = dicParamater["Company"].ToString().Trim();
            strExcelFile = dicParamater["ExcelFile"].ToString().Trim();
            #region Excel  columns
            columns.Add("STARTDATE");
            columns.Add("NAME");
            columns.Add("ORDERNO");
            columns.Add("FPOS");
            columns.Add("ARTICLE");
            columns.Add("YARN");
            columns.Add("FDDIS");
            columns.Add("QTY");
            columns.Add("UNIT");
            columns.Add("REQDATE");
            columns.Add("ENDDATE");
            columns.Add("GREIGE");
            columns.Add("WARP");
            //columns.Add("RATE");
            columns.Add("TECHDATE");
            columns.Add("TECHDAT");
            columns.Add("PODATE");
            columns.Add("PODAT");
            columns.Add("GPSDATE");
            columns.Add("GPSDAT");
            columns.Add("GPEDATE");
            columns.Add("GPEDAT");
            columns.Add("VWDATE");
            columns.Add("VWDAT");
            columns.Add("PRSDATE");
            columns.Add("PRSDAT");
            columns.Add("PREDATE");
            columns.Add("PREDAT");
            columns.Add("VADATE");
            columns.Add("VADAT");
            columns.Add("SHIPDATE");
            columns.Add("SHIPDAT");
            columns.Add("BEAM");
            columns.Add("FACTORY");
            columns.Add("SUPPLIER");
            columns.Add("GPFACTORY");
            #endregion           						
           /*STARTDATE	NAME	ORDERNO	FPOS	ARTICLE	YARN	FDDIS	QTY	UNIT	REQDATE	ENDDATE	
                    GREIGE	WARP	RATE	TECHDATE	TECHDAT	PODATE	PODAT	GPSDATE	GPSDAT	GPEDATE	GPEDAT	
                    VWDATE	VWDAT	PRSDATE	PRSDAT	PREDATE	PREDAT	VADATE	VADAT	SHIPDATE	SHIPDAT	BEAM	
                    FACTORY	SUPPLIER	GPFACTORY	STATUS*/
        }
        #region------------------------------Function------------------------

        public void FillInExcelData(ArrayList columns, DataSet setSoruce, int xStart = 2, int yStart = 1)
        {
            try
            {
                int x = xStart, y = yStart;
                DataTable dtSoruce = setSoruce.Tables["VKPOS"];
                foreach (DataRow dataRow in dtSoruce.Rows)
                {
                    y = yStart;
                    foreach (string column in columns)
                    {
                        exAgent.SetCellValue(x, y, dataRow[column].ToString());
                        y++;
                    }
                    x++;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        
        public override void WriteExcelReport(string fileType)
        {
            string filename = "";
            string sheetName = "";
            string Standard = "DSTDYARN";
            strExcelFile = @"DST\DSTInventory.xls";
            string filePath = @"C:\intex.w\Report\" + strExcelFile;
            exAgent.Open(filePath);
            //exAgent.Company = strCompany;
            exAgent.strExcelFile = strExcelFile;
            string filedate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            filename = @"交期跟踪表" + filedate + ".xls"; 
            sheetName = DateTime.Now.ToShortTimeString().Replace(":", "_").Replace(" ", "_").Replace("/", "_");
            exAgent.CreateNewSheet(filename, Standard, sheetName);
            FillInExcelData(columns, dsSource, 3, 1);             
            base.WriteExcelReport("OpenExcel");
        }
        
        #endregion
    }
}